package com.prothink.threadadmindemo.util;

import org.apache.commons.lang3.RandomUtils;

/**
 * @author mayanping
 * @title: PwdUtil
 * @projectName ThreadAdminDemo
 * @description: TODO
 * @date 2024/9/1808:53
 */
public class PwdUtil {
    /**
     * 生成一个随机的密码：数字+字母组合，长度为6
     * a-z 大写小
     * 0-9: >= 1 <= 5
     * 长度为6
     * @return
     */
    public static String generatorPassword(){
        String password = "";
        //numSize控制密码里面的数字的长度是几位
        int numSize = RandomUtils.nextInt(1, 6);
        System.out.println("数字密码的长度： " + numSize);
        for(int i=0; i<numSize; i++){
            int num = RandomUtils.nextInt(0,10);
            password += num;
        }

        int charNum = 6 - numSize;
        System.out.println("字母的密码的长度： " + charNum);
        for(int i=0; i< charNum; i++){
            int num = RandomUtils.nextInt(0, 26);
            char randomChar;
            if(RandomUtils.nextInt(0,2) != 0){
                //小写
                randomChar =(char) ('a' + num);
            }else{
                //大写
                randomChar =(char) ('A' + num);
            }
            password += randomChar;
        }
        System.out.println(password);
        return password;
    }

    public static void main(String[] args) {
        PwdUtil.generatorPassword();

        // a + (0-25)
        // A + (0-25)
//        System.out.println((char)('a' + 25));
//        System.out.println((char)('A' + 25));
    }
}
